package com.example.myapplication.adpter;

import android.graphics.Color;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.blankj.utilcode.util.ToastUtils;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.myapplication.R;
import com.example.myapplication.entiy.VideoEntity;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;

import java.util.List;

public class VideoAdapter extends BaseMultiItemQuickAdapter<VideoEntity.DataBean, BaseViewHolder> {
    public VideoAdapter(@Nullable List<VideoEntity.DataBean> data) {
        super(data);
        addItemType(0, R.layout.item_video);
        addItemType(1, R.layout.item_video);
        addItemType(2, R.layout.item_video);
        addItemType(5, R.layout.item_video);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, VideoEntity.DataBean bean) {
        switch (bean.getItemType()){
            case 0:
            case 1:
            case 2:
            case 5:
                StandardGSYVideoPlayer gsy = holder.findView(R.id.gsy);
                String caption = bean.getCaption();
                SpannableStringBuilder builder = new SpannableStringBuilder(caption);
                builder.setSpan(new ForegroundColorSpan(Color.RED),0,4, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
                ClickableSpan span = new ClickableSpan() {
                    @Override
                    public void onClick(@NonNull View widget) {
                        ToastUtils.showLong("点击了文字");
                    }
                };
               /* builder.setSpan(span,2,4,Spanned.SPAN_INCLUSIVE_INCLUSIVE);
                caption.removeMethod(LinkMovementMethod.getInstance());*/
                gsy.setUp(bean.getVideopath(),true,builder.toString());
                gsy.startPlayLogic();

                //切换全屏时使用
                gsy.setShowFullAnimation(true);
                gsy.setLockLand(true);
                gsy.setAutoFullWithSize(false);
                ImageView ivDianzan = holder.findView(R.id.iv_dianzan);
                if(bean.getDianzan()==1){
                    ivDianzan.setImageResource(R.drawable.ic_xihuanred);
                }else{
                    ivDianzan.setImageResource(R.drawable.ic_xihuan);
                }
                break;
        }
    }
}
